#include <stdint.h>


typedef int (*callT)();

#define CALL(addr,...) ((callT)(addr))(__VA_ARGS__)
#define CALLT(addr,...) ((callT)(addr+1))(__VA_ARGS__)

//没有问题
int JMP8023640_r1(uint32_t r0){
    uint32_t *r5 = (void*)0x3004DF0;
    uint8_t *r2 = (void*)0x203A954;

    uint16_t v1 =  *(uint16_t*)(r5[0]+r2[0x12]*2);
    if(
        CALL(0x80174E5,v1)
        && CALL(0x80172F0+1,v1) != 4
        && CALL(0x80172F0+1,v1) != 0xc
        && (!(CALL(0x8017314+1,v1)&1) || CALL(0x801631C+1,v1)<<24)
    ){
        if(CALL(0x802881C+1,v1)<<24){
            return 1;
        }
        else{
            return 2;
        }
    }
    else{
        return 1;
    }
}


//OK，修改成功
int JMP802FB98_r1(uint32_t r0){
    uint32_t v0 = *(uint8_t*)(0x203A954+0xc);

    uint32_t r8 = CALL(0x8017294+1,
    *(uint16_t*)(CALL(0x8019108+1,v0) + 0x1e +
    *(uint8_t*)(0x203A954+0x12) * 2));

    *(uint8_t*)(0x203A4E8+0x7e) = 0;
    if(r8==0x9){
        r8 = 0x21 + 0x4b;
    }
    uint32_t v1 = r8 - 0x4b;
    if(v1<=0x76){
        switch (v1)
        {
        case 0:
        case 1:
        case 2:
        case 3:
            CALL(0x802EAD0+1,r0);break;
        case 6:
        case 7:
        case 8:
            CALL(0x802EF48+1,r0);break;
        case 0x5b:
            CALL(0x802F104+1,r0);break;
      case 4:
        CALLT(0x802F08C,r0);
        break;
      case 5:
        CALLT(0x802EB58,r0);
        break;
      case 0xA:
        CALLT(0x802EE30,r0);
        break;
      case 0xE:
        CALLT(0x802EBC4,r0);
        break;
      case 9:
        CALLT(0x802EEE4,r0);
        break;
      case 0xD:
        CALLT(0x802F1A0,r0);
        break;
      case 0xC:
        CALLT(0x802F1E0,r0);
        break;
      case 0x25:
        CALLT(0x802F3AC,r0);
        break;

    case 0x21:
      case 0x57:
        CALLT(0x802F2A0,v1, 10);
        break;
      case 0x22:
        CALLT(0x802F304,v1);
        break;
      case 0x23:
        CALLT(0x802F370,v1);
        break;
      case 0x24:
        CALLT(0x802F3F0,v1);
        break;
      case 0x1E:
      case 0x1F:
      case 0x20:
      case 0x2E:
        CALLT(0x802F430);
        break;

      case 0x19:
      case 0x1A:
      case 0x1B:
      case 0x1C:
      case 0x1D:
      case 0x3D:
      case 0x3F:
      case 0x4C:
      case 0x4D:
      case 0x4E:
      case 0x76:
        //代码太多了，反正不会执行到这一步
        // uint32_t v6 = sub_8019108(*(uint8_t*)(0x203A954+0xc)) + 30 + 2 * *(uint8_t*)(0x203A4E8+0x12);
        // v203A5B2 = *(_WORD *)v6;
        // v203A532 = *(_WORD *)v6;
        // v7 = sub_8019108(v203A960);
        // v203A5B0 = sub_80168D0(v7);
        // v203A530 = v203A5B0;
        // v203A5D7 = -1;
        // sub_80D1730(v1);

        default:
            break;
        }
    }
    return 0;
}
